package cc.wsyw126.java.nowcoder.sword_offer;

/**
 * Created by Administrator on 2017/4/17.
 */
public class Match {
    public boolean match(char[] str, char[] pattern) {
        if (str.length == 0 && pattern.length ==0) return true;
        if (str == null || pattern == null || str.length ==0 || pattern.length ==0) return false;

        int position  =0;
        for (int i = 0; i < pattern.length; i++) {
            if (pattern[i] == '*') {
                if (i==0) return false;
                boolean temp = false;
                do {
                    char c = pattern[i-1];
                    temp = isEquals(c, str[position++]);
                }while (temp);
            }
            if (!isEquals(pattern[i], str[position++])) {
                return false;
            }
        }
        return true;
    }

    // TODO: 2017/4/17 不完善
    private boolean isEquals(char a, char b){
        if (a == '.' ||b == '.') return true;
        if (a == b) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        char[] a = new char[]{'a','b'};
        char[] b = new char[]{'a','b'};
        if (a.equals(b)) System.out.println(true);
    }
}
